﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
	<head>
	<base href="<%=basePath%>">
	<!-- jsp文件头和头部 -->
	<%@ include file="../main/main_top.jsp"%> 
	</head> 
<body>
<div class="container-fluid" id="main-container">
	<div id="page-content" class="clearfix">
		<div class="row-fluid">
				<!-- 检索  -->
				<form action="newuser/listUsersData.do" method="post" name="userForm" id="userForm">
				<input type="hidden" name="currentselectorganid" id="currentselectorganid" value="${pageData.currentselectorganid }"/>
				<input type="hidden" name="currentorganid" id="currentorganid" value="${pageData.currentorganid }"/>
				<table>
					<tr>
						<td>
							<span class="input-icon">
								<input autocomplete="off" id="nav-search-input" type="text" name="username" value="${pageData.username }" placeholder="这里输入关键词" />
								<i id="nav-search-icon" class="icon-search"></i>
							</span>
						</td>
						<td><input class="span10 date-picker" name="lastloginbegin" id="lastloginbegin"  value="${pageData.lastloginbegin}" type="text" data-date-format="yyyy-mm-dd" readonly="readonly" style="width:88px;" placeholder="开始日期" title="最近登录开始"/></td>
						<td><input class="span10 date-picker" name="lastloginend" id="lastloginend"  value="${pageData.lastloginend}" type="text" data-date-format="yyyy-mm-dd" readonly="readonly" style="width:88px;" placeholder="结束日期" title="最近登录结束"/></td>
						<td style="vertical-align:top;"> 
						 	<select class="chzn-select" name="roleid" id="roleid" data-placeholder="请选择角色" style="vertical-align:top;width: 120px;">
							<option value="">全部</option>
							<c:forEach items="${roleList}" var="role">
								<option value="${role.roleid }" <c:if test="${pageData.roleid==role.roleid}">selected</c:if>>${role.rolename }</option>
							</c:forEach>
						  	</select>
						</td>
						<c:if test="${operPrivilegePageData.view != null && operPrivilegePageData.view == 1 }">
							<td style="vertical-align:top;"><button class="btn btn-mini btn-light" onclick="search();" title="检索"><i id="nav-search-icon" class="icon-search"></i></button></td>
						</c:if>
						<%-- <c:if test="${operPrivilegePageData.download != null && operPrivilegePageData.download == 1 }">
							<td style="vertical-align:top;"><a class="btn btn-mini btn-light" onclick="exportExcel();" title="导出到EXCEL"><i id="nav-search-icon" class="icon-download-alt"></i></a></td>
						</c:if>
						<c:if test="${operPrivilegePageData.upload != null && operPrivilegePageData.upload == 1 }">
							<td style="vertical-align:top;"><a class="btn btn-mini btn-light" onclick="importExcel();" title="从EXCEL导入"><i id="nav-search-icon" class="icon-cloud-upload"></i></a></td>
						</c:if> --%>
						<c:if test="${operPrivilegePageData.view != null && operPrivilegePageData.view == 1 }">
							<td style="vertical-align:top;"><a class="btn btn-mini btn-light" onclick="clearCondition();" title="清空查询条件"><i id="nav-search-icon"></i>清空查询条件</a></td>
						</c:if>
					</tr>
				</table>
				<!-- 检索  -->
				
				<table id="table_report" class="table table-striped table-bordered table-hover">
					<thead>
						<tr>
							<th class="center">
								<label><input type="checkbox" id="zcheckbox" /><span class="lbl"></span></label>
							</th>
							<th>序号</th>
							<th>用户名</th>
							<th>姓名</th>
							<th>电话号码</th>
							<th>角色</th>
							<th>上级操作员</th>
							<th><i class="icon-envelope"></i>邮箱</th>
							<th>登录次数</th>
							<th><i class="icon-time hidden-phone"></i>最近登录</th>
							<th><i class="icon-time hidden-phone"></i>创建时间</th>
							<th><i class="icon-time hidden-phone"></i>解锁时间</th>
							<th>上次登录IP</th>
							<th class="center">状态</th>
							<th>所属机构</th>
							<th class="center">操作</th>
						</tr>
					</thead>
					<tbody>
						
					<!-- 开始循环 -->	
					<c:choose>
						<c:when test="${not empty userList}">
							<c:forEach items="${userList}" var="user" varStatus="vs">
								<tr>
									<td class='center' style="width: 30px;">
										<label><input type='checkbox' name='ids' value="${user.operid }" id="${user.email }" alt="${user.phonenumber }"/><span class="lbl"></span></label>
									</td>
									<td class='center' style="width: 30px;">${vs.index+1}</td>
									<td>${user.username }</td>
									<td>${user.nickname }</td>
									<td>${user.phonenumber }</td>
									<td>${user.rolename }</td>
									<td>${user.parentopername }</td>
									<td>
										<!--<a title="发送电子邮件" style="text-decoration:none;cursor:pointer;" onclick="sendEmail('${user.email }');">${user.email }&nbsp;<i class="icon-envelope"></i></a>-->
										${user.email }&nbsp;<i class="icon-envelope"></i>
									</td>
									<td>${user.logincount}</td>
									<td>${user.logintime}</td>
									<td>${user.createtime}</td>
									<td>${user.unlocktime}</td>
									<td>${user.loginip}</td>
									<td style="width: 60px;" class="center">
										<c:if test="${user.isvalid == '0' }"><span class="label label-important arrowed-in">冻结</span></c:if>
										<c:if test="${user.isvalid == '1' }"><span class="label label-success arrowed">正常</span></c:if>
									</td>
									<td>${user.organname}</td>
									<td style="width: 60px;">
										<div class='hidden-phone visible-desktop btn-group'>
											<!-- 
											<a class='btn btn-mini btn-warning' title="发送短信" onclick="sendSms('${user.phonenumber }');"><i class='icon-envelope'></i></a>
											 -->
											<c:if test="${operPrivilegePageData.edit != null && operPrivilegePageData.edit == 1 }">
												<a class='btn btn-mini btn-info' title="编辑" onclick="editUser('${pageData.currentselectorganid }', '${user.operid }');"><i class='icon-edit'></i></a>
											</c:if>
											<a class='btn btn-mini btn-info' title="修改密码" onclick="editUserPassword('${pageData.currentselectorganid }', '${user.operid }');"><i class='icon-adjust'></i></a>
												<c:if test="${pageData.currentselectorganid != pageData.currentorganid }">
													<c:if test="${operPrivilegePageData.delete != null && operPrivilegePageData.delete == 1 }">
												 		<a class='btn btn-mini btn-danger' title="删除" onclick="delUser('${pageData.currentselectorganid }', '${user.operid }','${user.username }');"><i class='icon-trash'></i></a>
												 	</c:if>
											 	</c:if>
										</div>
									</td>
								</tr>
							</c:forEach>
						</c:when>
						<c:otherwise>
							<tr class="main_info">
								<td colspan="16" class="center">没有相关数据</td>
							</tr>
						</c:otherwise>
					</c:choose>
					</tbody>
				</table>
				
			<div class="page-header position-relative">
				<table style="width:100%;">
					<tr>
						<td style="vertical-align:top;">
							<a class="btn btn-small btn-success" onclick="addUser('${pageData.currentselectorganid }');">新增</a>
							<a title="批量删除" class="btn btn-small btn-danger" onclick="makeAll('确定要删除选中的数据吗?');" ><i class='icon-trash'></i></a>
						</td>
						<td style="vertical-align:top;"><div class="pagination" style="float: right;padding-top: 0px;margin-top: 0px;">${page.pageStr}</div></td>
					</tr>
				</table>
			</div>
			</form>
		<!-- PAGE CONTENT ENDS HERE -->
	  </div><!--/row-->
	</div><!--/#page-content-->
</div><!--/.fluid-container#main-container-->
		<!-- 返回顶部  -->
		<a href="#" id="btn-scroll-up" class="btn btn-small btn-inverse">
			<i class="icon-double-angle-up icon-only"></i>
		</a>
		<!-- 引入 -->
		<script type="text/javascript" src="static/1.9.1/jquery.min.js"></script>
		<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
		<script type="text/javascript" src="static/js/bootstrap.min.js"></script>
		<script type="text/javascript" src="static/js/ace-elements.min.js"></script>
		<script type="text/javascript" src="static/js/ace.min.js"></script>
		
		<script type="text/javascript" src="static/js/bootbox.min.js"></script><!-- 确认窗口 -->
		<!-- 引入 -->
		
		<!--引入弹窗组件start-->
		<script type="text/javascript" src="plugins/attention/zDialog/zDrag.js"></script>
		<script type="text/javascript" src="plugins/attention/zDialog/zDialog.js"></script>
		<!--引入弹窗组件end-->
		
		<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script><!-- 下拉框 -->
		<script type="text/javascript" src="static/js/bootstrap-datepicker.min.js"></script><!-- 日期框 -->
		<!-- 引入 -->
		
		<script type="text/javascript" src="static/js/jquery.tips.js"></script><!--提示框-->
		<script type="text/javascript">
		
		//$(window.parent.hangge());
		$(top.hangge());
		function clearCondition(){
			$("#nav-search-input").val("");
			$("#lastloginbegin").val("");
			$("#lastloginend").val("");
		}
		
		//检索
		function search(){
			//window.parent.jzts();
			top.jzts();
			$("#userForm").submit();
		}
		
		//去发送电子邮件页面
		function sendEmail(email){
			 //window.parent.jzts();
			 top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="发送电子邮件";
			 diag.URL = '<%=basePath%>/head/goSendEmail.do?email='+email;
			 diag.Width = 600;
			 diag.Height = 470;
			 diag.CancelEvent = function(){ //关闭事件
				diag.close();
			 };
			 diag.show();
		}
		
		//去发送短信页面
		function sendSms(phone){
			 //window.parent.jzts();
			 top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="发送短信";
			 diag.URL = '<%=basePath%>/head/goSendSms.do?PHONE='+phone+'&msg=appuser';
			 diag.Width = 600;
			 diag.Height = 265;
			 diag.CancelEvent = function(){ //关闭事件
				diag.close();
			 };
			 diag.show();
		}
		
		//新增
		function addUser(currentselectorganid){
			 //window.parent.jzts();
			 top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="新增";
			 diag.URL = '<%=basePath%>/newuser/goAddUser.do?currentselectorganid=' + currentselectorganid;
			 diag.Width = 350;
			 diag.Height = 430;
			 diag.CancelEvent = function(){ //关闭事件
				 if(diag.innerFrame.contentWindow.document.getElementById('centerOfMainFrame').style.display == 'none'){
					 if('${page.currentPage}' == '0'){
						 //alert(${page.currentPage});
						 //window.parent.jzts();
						 //setTimeout("self.location.reload()",100);
						 //alert(${page.currentPage} + 1);
						 window.location.href='<%=basePath%>/newuser/listUsersData.do?currentselectorganid=' + currentselectorganid;
					 }else{
						 nextPage(${page.currentPage});
					 }
				}
				diag.close();
			 };
			 diag.show();
		}
		
		//修改
		function editUser(currentselectorganid, operid){
			 //window.parent.jzts();
			 top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="修改";
			 diag.URL = '<%=basePath%>/newuser/goEditUser.do?currentselectorganid=' + currentselectorganid + '&operid='+operid;
			 diag.Width = 350;
			 diag.Height = 330;
			 diag.CancelEvent = function(){ //关闭事件
				if(diag.innerFrame.contentWindow.document.getElementById('centerOfMainFrame').style.display == 'none'){
					nextPage(${page.currentPage});
				}
				diag.close();
			 };
			 diag.show();
		}
		
		//修改密码
		function editUserPassword(currentselectorganid, operid){
			 //window.parent.jzts();
			 top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="修改密码";
			 diag.URL = '<%=basePath%>/newuser/goEditUserPassword.do?currentselectorganid=' + currentselectorganid + '&operid='+operid;
			 diag.Width = 330;
			 diag.Height = 130;
			 diag.CancelEvent = function(){ //关闭事件
				if(diag.innerFrame.contentWindow.document.getElementById('centerOfMainFrame').style.display == 'none'){
					nextPage(${page.currentPage});
				}
				diag.close();
			 };
			 diag.show();
		}
		
		//删除
		function delUser(currentselectorganid, operid, msg){
			bootbox.confirm("确定要删除["+msg+"]吗? 删除后数据不可恢复!", function(result) {
				if(result) {
					var url = "<%=basePath%>/newuser/deleteUser.do?currentselectorganid=' + currentselectorganid + '&operid="+operid+"&tm="+new Date().getTime();
					$.get(url,function(data){
						if(data=="success"){
							nextPage(${page.currentPage});
						}
					});
				}
			});
		}
		
		//批量操作
		function makeAll(msg){
			bootbox.confirm(msg, function(result) {
				if(result) {
					var str = '';
					var emstr = '';
					var phones = '';
					for(var i=0;i < document.getElementsByName('ids').length;i++)
					{
						  if(document.getElementsByName('ids')[i].checked){
						  	if(str=='') str += document.getElementsByName('ids')[i].value;
						  	else str += ',' + document.getElementsByName('ids')[i].value;
						  	
						  	if(emstr=='') emstr += document.getElementsByName('ids')[i].id;
						  	else emstr += ';' + document.getElementsByName('ids')[i].id;
						  	
						  	if(phones=='') phones += document.getElementsByName('ids')[i].alt;
						  	else phones += ';' + document.getElementsByName('ids')[i].alt;
						  }
					}
					if(str==''){
						bootbox.dialog("您没有选择任何内容!", 
							[
							  {
								"label" : "关闭",
								"class" : "btn-small btn-success",
								"callback": function() {
									//Example.show("great success");
									}
								}
							 ]
						);
						
						$("#zcheckbox").tips({
							side:3,
				            msg:'点这里全选',
				            bg:'#AE81FF',
				            time:8
				        });
						
						return;
					}else{
						if(msg == '确定要删除选中的数据吗?'){
							$.ajax({
								type: "POST",
								url: 'newuser/deleteAllUser.do?tm='+new Date().getTime(),
						    	data: {operids:str},
								dataType:'json',
								//beforeSend: validateData,
								cache: false,
								success: function(data){
									 $.each(data.list, function(i, list){
											nextPage(${page.currentPage});
									 });
								}
							});
						}else if(msg == '确定要给选中的用户发送邮件吗?'){
							sendEmail(emstr);
						}else if(msg == '确定要给选中的用户发送短信吗?'){
							sendSms(phones);
						}
					}
				}
			});
		}
		</script>
		
		<script type="text/javascript">
		$(function() {
			//日期框
			$('.date-picker').datepicker();
			
			//下拉框
			$(".chzn-select").chosen(); 
			$(".chzn-select-deselect").chosen({allow_single_deselect:true}); 
			
			//复选框
			$('table th input:checkbox').on('click' , function(){
				var that = this;
				$(this).closest('table').find('tr > td:first-child input:checkbox')
				.each(function(){
					this.checked = that.checked;
					$(this).closest('tr').toggleClass('selected');
				});
					
			});
			
		});
		
		//导出excel
		function exportExcel(){
			var username = $("#nav-search-input").val();
			var lastloginbegin = $("#lastloginbegin").val();
			var lastloginend = $("#lastloginend").val();
			var roleid = $("#roleid").val();
			window.location.href='<%=basePath%>/newuser/exportExcel.do?username='+username+'&lastloginbegin='+lastloginbegin+'&lastloginend='+lastloginend+'&roleid='+roleid;
		}
		
		//打开上传excel页面
		function importExcel(){
			 top.jzts();
			 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="EXCEL 导入到数据库";
			 diag.URL = '<%=basePath%>/newuser/importExcel.do';
			 diag.Width = 300;
			 diag.Height = 150;
			 diag.CancelEvent = function(){ //关闭事件
				diag.close();
			 };
			 diag.show();
		}
		</script>
	</body>
</html>

